import React, { Component } from 'react';
import {BasicForm} from '../form/BasicForm';
import { Row, Col, message,Input, Icon,Form, Cascader, DatePicker, Button, Tooltip, Popconfirm } from 'antd';
import {
    GetInfoSetData,
} from '../common/CommonFunction';

import '../../style/Employee.less';

/*获取指定标签内的数据*/
async function savePropertyData(option, success) {

    console.log(option);
}



let infosetCode = 'HRMB0011';
let  schemaJson = [
    {canEdit:true,className:'col-xs-6',code:'ContractNo',dataSourceParameter:null,
    dataType:0, defaultValue:null,editMode:'1',isRequired:false,linkFieldCode:null,
    localizationName:'合同编号',matchExpression:null,max:null,maxLength:20,
    min:null,minLength:null,selectedItemList:[],sortIndex:0,validateExpression:null},

    {canEdit:true,className:'col-xs-6',code:'ContractName',dataSourceParameter:null,
    dataType:0, defaultValue:null,editMode:'1',isRequired:false,linkFieldCode:null,
    localizationName:'合同名称',matchExpression:null,max:null,maxLength:20,
    min:null,minLength:null,selectedItemList:[],sortIndex:1,validateExpression:null},

    {canEdit:true,className:'col-xs-6',code:'Name',dataSourceParameter:null,
    dataType:0, defaultValue:null,editMode:'1',isRequired:false,linkFieldCode:null,
    localizationName:'名称',matchExpression:null,max:null,maxLength:20,
    min:null,minLength:null,selectedItemList:[],sortIndex:2,validateExpression:null},

    {canEdit:true,className:'col-xs-6',code:'Age',dataSourceParameter:null,
    dataType:0, defaultValue:null,editMode:'4',isRequired:false,linkFieldCode:null,
    localizationName:'年龄',matchExpression:null,max:null,maxLength:null,
    min:null,minLength:null,selectedItemList:[],sortIndex:3,validateExpression:null},

    {canEdit:true,className:'col-xs-6',code:'Birth',dataSourceParameter:null,
    dataType:0, defaultValue:null,editMode:'2',isRequired:false,linkFieldCode:null,
    localizationName:'生日',matchExpression:null,max:null,maxLength:null,
    min:null,minLength:null,selectedItemList:[],sortIndex:4,validateExpression:null},

    {canEdit:true,className:'col-xs-6',code:'Sex',dataSourceParameter:null,
    dataType:0, defaultValue:null,editMode:'3',isRequired:false,linkFieldCode:null,
    localizationName:'性别',matchExpression:null,max:null,maxLength:20,
    min:null,minLength:null,selectedItemList:[{disabled:false,linkValue:null,name:'男',sortIndex:0,value:'1'},{disabled:false,linkValue:null,name:'女',sortIndex:1,value:'2'}],sortIndex:5,validateExpression:null}

    ];

let schema = {columnList:[],fieldList:schemaJson,infoSetCode:'HRMB0011',name:'合同',subFieldList:[],subTypes:[],timeConstraints:[{subTypeCode:'',timeType:2}]};




class TestForm extends Component{
    constructor(props){
        super(props);
        this.state = {
            Value: null,
            viewHistory: false,
            tableData: [],
            searchDate: [],
            afterSeachData: [],
            currentControlData: [],
            historyData: null,
        };
    }



     /*取消编辑信息集数据*/
     Cancel() {
        let self = this;
        let infoSetCode = self.props.infoSetCode;
        if (self.props.handleCancel) {
            self.props.handleCancel(infoSetCode);
        }
    }

    /*提交信息集的数据*/
    SubmitPorperty() {
        let self = this;
        let totalJson = [];
        let jsonData = null;
        let infoSetCode = self.props.infoSetCode;
        let queryInfo = self.props.queryInfo;
        /*生成页面展示的所有InfoSet的信息，并转换成数组，用于保存*/
        let infoSetDataList = GetInfoSetData(self, schema);

        console.log('infoSetDataList');
        console.log(infoSetDataList);

        let dataList = [];
        infoSetDataList.infoSetData.map(function (data, i) {
            dataList.push(
                {
                    beginDate: data.begin,
                    endDate: data.end,
                    fieldValueList: data.fieldValueList,
                    subTypeCode: data.subTypeCode
                });
        });

        jsonData =
        {
            infoSetCode: infoSetCode,
            dataList: dataList,
            operation: self.props.operationType
        };
        if (jsonData != null) {
            totalJson.push(jsonData);
        }

        let submitJson =
        {
            propertyList: totalJson,
            hRObjectDto: {objectID: queryInfo.objectId, beginDate: queryInfo.beginDate, endDate: queryInfo.endDate}
        };
        console.log("submitJson", submitJson);
        savePropertyData(submitJson, (resData)=> {
            message.config({
                top: "50%",
                duration: 2,
            });
            message.success("保存成功!", 2);
            let infoSetValue = self.CollectInfoSetData();
            /*设置保存后数据对应的数据显示的state*/
            if (self.props.handleSubmitPropertyData) {
                self.props.handleSubmitPropertyData(infoSetCode, infoSetValue);
            }
        });
    }

    


    render(){
        let self = this;

       
        return (<div>
                <BasicForm schema={schema} rootComponent={self} currentOperationStepKey ={ infosetCode } ></BasicForm>
                <Row className="c-tar c-mt-20">
                        <Button onClick={self.Cancel.bind(self)} className="btn-default c-mr-20">取消</Button>
                        <Button className="btn-primary"  onClick={self.SubmitPorperty.bind(self)}>保存</Button>
                </Row>          
                

        </div>)

    }
}
TestForm = Form.create()(TestForm);
export {
    TestForm as TestForm
}